from selenium.webdriver.common.keys import Keys
from untils.CSVREADER import EXCEL
# from conftest import driver
from Pages.BasePage import BasePage
import time
from untils.random_email import random_email






# driver = driver()


class PLS_yq(BasePage):
    def __init__(self, driver):
        super().__init__(driver)
        # 全站搜索
        self.url = self.excel.get_element("Home", "url")[0]
        self.search = self.excel.get_element("Home", "search")
        self.input = self.excel.get_element("Home", "input")
        # self.url = self.yamlreader.get_url("PLS_Home", "url")
        # self.search = self.yamlreader.get_element("PLS_Home","search")
        # self.input = self.yamlreader.get_element("PLS_Home","input")

        # 业务联络
        self.business_button = self.excel.get_element("business", "business_button")
        self.business_type = self.excel.get_element("business", "business_type")
        self.name = self.excel.get_element("business", "name")
        self.email = self.excel.get_element("business", "email")
        self.positions = self.excel.get_element("business", "positions")
        self.company = self.excel.get_element("business", "company")
        self.phone = self.excel.get_element("business", "phone")
        self.Captcha = self.excel.get_element("business", "Captcha")
        self.code = self.excel.get_element("business", "code")
        self.agreement = self.excel.get_element("business", "agreement")
        self.submit = self.excel.get_element("business", "submit")

        # 联系我们（搜索）
        self.contact = self.excel.get_element("contact_search","contact")
        self.selectKW = self.excel.get_element("contact_search", "selectKW")
        self.contactUsSearch = self.excel.get_element("contact_search", "contactUsSearch")

        # 订阅“普洛斯纵览”
        self.input_email = self.excel.get_element("subscribe", "input_email")
        self.click_subscribe = self.excel.get_element("subscribe", "click_subscribe")
        self.assert_subscribe = self.excel.get_element("subscribe", "assert_subscribe")



    # 全站搜索
    def test_search(self, content):
        self.get(self.url)
        self.find_element(self.search).click()
        self.find_element(self.input).send_keys(content, Keys.ENTER)
        self.handoff_handle()
        time.sleep(2)
        return self.get_current_url()

    # 业务联络
    def test_business(self, name, positions, company, phone, code):
        self.get(self.url)
        self.find_element(self.business_button).click()
        self.find_element(self.business_type).click()
        self.find_element(self.name).send_keys(name)
        self.find_element(self.email).send_keys(random_email())
        self.find_element(self.positions).send_keys(positions)
        self.find_element(self.company).send_keys(company)
        self.find_element(self.phone).send_keys(phone)
        self.find_element(self.Captcha).click()
        self.find_element(self.code).send_keys(code)
        self.find_element(self.agreement).click()
        self.find_element(self.submit).click()
        time.sleep(5)

    # 联系我们（搜索）
    def test_contact_search(self, selectKW):
        self.get(self.url)
        self.find_element(self.contact).click()
        self.find_element(self.selectKW).send_keys(selectKW)
        self.find_element(self.contactUsSearch).click()

    # 订阅“普洛斯纵览”
    def test_subscribe(self):
        self.get(self.url)
        self.find_element(self.input_email).send_keys(random_email())
        self.find_element(self.click_subscribe).click()
        time.sleep(10)
        self.element = self.WebDriver_Wait(self.assert_subscribe)
        return self.element.text


